const fs = require('fs');
const child_process = require('child_process');
const iconv = require('iconv-lite');
const filePath = "D:\\wwwroot\\xxx\\log.txt" //配置保存的路径

child_process.exec('git log   --since =1.days --oneline --author=duanchangpeng  >log.txt', (error, stdout, stderr) => {
    if (error) {
        console.error(`exec error: ${error}`);
        return;
    }
    fs.readFile(filePath, function (err, date) {
        if (err) {
            return console.log(err);
        }
        let newdateString = date.toString().split(' ')
        let charts = '';
        charts = newdateString.map(function (item) {
         if(item.length !== 6 )return item
        })
        console.log('charts',charts.toString())
        let cliptext = "我今天完成的任务是：" + charts.toString()

        console.log(cliptext + "（直接粘贴内容到日报即可)");

        child_process.exec('clip').stdin.end(iconv.encode(cliptext, 'utf-8'));
        // child_process.exec('clip').stdin.end(cliptext);
    });
});



